/*
  axios.get() 查
  axios.post() 增
  axios.put() 改
  axios.delete() 删
*/

class Axios {
  get(url, data, formType) {
    return this.request('get', url, data, formType);
  }
  post(url, data, formType) {
    return this.request('post', url, data, formType);
  }
  put(url, data, formType) {
    return this.request('put', url, data, formType);
  }
  delete(url, data, formType) {
    return this.request('delete', url, data, formType);
  }
  request(method, url, data, formType) {
    return new Promise((resolve, reject) => {
      let contentType = formType ? "application/x-www-form-urlencoded" : "application/json";
      wx.request({
        url: url,
        method: method,
        data: data,
        header: {
          "content-type": contentType
        },
        success(res) {
          //成功的回调
          resolve(res);
        },
        fail(err) {
          //失败的回调
          reject(err);
        }
      })
    })
  }
}
module.exports = new Axios();